<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="description" content="">
    <meta name="HandheldFriendly" content="True">
    <meta name="MobileOptimized" content="320">
    <meta name="viewport" content="width=device-width, initial-scale=1, minimal-ui, user-scalable=no">
    <meta http-equiv="cleartype" content="on">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/assets/restaurant/css/style.css">
    <link rel="stylesheet" href="/assets/public/layermobile/css/layer.css">
</head>
<body>
<div class="wraper">
    <header class="text-center font-white font-36">
        <a href="#" class="back"><img src="/assets/restaurant/images/back.png" alt=""></a>
        取菜
        <a href="#" class="right"><img src="/assets/restaurant/images/Refresh.png" alt=""
                                       onclick="window.location.reload();"></a>
    </header>
    <div class="tb-mode search">
        <div class="tb-cell input">
            <input type="text" id="good_tj" class="font-gray2 font-28 " placeholder="请输入菜名 / 桌号"
                   value="{BEESCRM:$good_tj}">
        </div>
        <a href="#" class="search_text font-28 font-white text-center tb-cell soso">搜索</a>
    </div>
    <div class="main">
        <div class="padding-20 js_tab">
            <div class="tab font-28 font-gray2 text-center tb-mode">
                <!--   <div class='tab-list tb-cell ' data-type="1">新菜单</div>-->
                <div class='tab-list tb-cell active' data-type="2">未取菜</div>
                <div class='tab-list tb-cell ' data-type="3">全部</div>
                <!-- <div class='tab-list tb-cell <if condition="$type eq 1"> active</if>'>全部</div>-->
            </div>
        </div>
        <div class="contain">
            <div class="contain_child"></div>
        </div>
        <!-- <div class="contain  clearfix hide"></div>-->
    </div>
    <div class="pop-box hide">
        <div class="pop-hint">
            <div class="font-40 text-center hint-txt"></div>
            <div class="tb-mode border-top">
                <a href="#" class="pop-btn font-32 tb-cell text-center">取消</a>
                <a href="#" class="pop-btn font-32 tb-cell text-center font-blue">确定</a>
            </div>
        </div>
    </div>
    <input type="hidden" class="type" value="">
    <input type="hidden" class="restaurantId" value="{BEESCRM:$restaurant_id}">

</div>
<include file="loadding"/>
</body>
<script src="/assets/restaurant/js/jquery-2.1.0.min.js"></script>
<script src="/assets/public/layermobile/layer.js"></script>
<script src="/assets/restaurant/js/public.js"></script>
<script>

    $(function () {
        var og_id;
        var type = $('.active').data('type');
        var restaurantId = $(".restaurantId").val();
        var window_height = $(window).height();
        var header_height = $('header').outerHeight(true);
        var search_height = $('.search').outerHeight(true);
        var tab_height = $('.js_tab').outerHeight(true);
        $('.contain').css('height', window_height - header_height - search_height - tab_height);
        var page = 1;
        var select_ajax = true;
        getData({type: type, restaurant_id: restaurantId,p:1});
        $('.tab').on('click', '.tab-list', function () {
            /*      var idx = $(this).index();
             $('.contain').eq(idx).removeClass('hide').addClass('show').siblings('.contain').addClass('hide').removeClass('show');*/
            $(this).addClass('active').siblings('.tab-list').removeClass('active');
            $('#good_tj').val('');
            /* var og_id=$()*/
            type = $(this).data('type');
            if (type == 3) {
                $('#good_tj').attr('placeholder', '请输入桌号')
            } else {
                $('#good_tj').attr('placeholder', '请输入菜名 / 桌号')
            }
            $('.contain_child').html('');
            page = 1;
            select_ajax = true;
            getData({type: type, restaurant_id: restaurantId, p: 1});
        });


        $(document).on('click', '.soso', function () {
            $('.contain_child').html('');
            var good_tj = $('#good_tj').val();
            getData({type: type, good_tj: good_tj, restaurant_id: restaurantId});
            /* window.location.href = "/restaurant/hdScreen/padindex?restaurant_id={BEESCRM:$restaurant_id}&good_tj=" + good_tj + "&type={BEESCRM:$type}";*/
        });

        $(".contain").scroll(function () {
            var viewH = $(this).height(),//可见高度
                contentH = $('.contain_child').outerHeight(),//内容高度
                scrollTop = $(this).scrollTop();//滚动高度
            if (scrollTop + viewH +1 >= contentH) {
                /*        alert(select_ajax);*/
                if (select_ajax) {
                    getData({type: type, restaurant_id: restaurantId, p: page});
                }
            }
        });

alert(111)

        function getData(field) {
            $.ajax({
                url: '/restaurantstyy/ZduScreen/padindex',
                type: 'POST',
                data: field,
                dataType: 'JSON',
                beforeSend: function () {
                    $('.circle-loadding').show();
                    select_ajax = false;
                },
                success: function (data) {
                    $('.circle-loadding').hide();
                    $('.show').html('');
                    if (data.status == 'S') {
                        $(".type").val(data.type);
                        var _html = '';
                        $.each(data.data, function (i, k) {
                            var key = i;
                            /*console.log(i);
                             console.log(data.data[i]);*/
                            var _num = '';
                            $.each(data.data[i], function (i, k) {
                                if (type == 2) {
                                    _num += '<a href="#" class="meals_number font-32" value ="' + k.og_id + '" data-ogid="' + k.og_id + '">' + k.order_num + '333号 </a>'

                                } else {
                                    var state = k.goods_status;
                                    if (state == 1) {
                                        state = '<span class="state">已上菜</span>';
                                    }
                                    if (state == 2) {
                                        state = '<span class="state state2">已取菜</span> ';
                                    } else {
                                        state = ' ';
                                    }
                                    _num += '<a href="#" class="meals_number">' + k.goods_name + '' + state + '</a>'

                                }
                            });
                            /*     if (type == 1) {
                             _html += '<div class=" half2 pull-left"><div class="tb-mode meals"><div class=" tb-cell font-28"><div class="font-48 name"> ' + key + ' </div> ' + _num + '</div><div class="tb-cell pull-right"><a href="#" class="font-32 order_btn text-center bg_green" data-type="1">上菜 </a> </div></div> </div>';
                             } else */
                            if (type == 2) {
                                _html += '<div class=" half2"><div class="tb-mode meals"><div class=" tb-cell font-28"><div class="font-48 name"> ' + key + ' </div> ' + _num + '</div><div class="tb-cell pull-right"><a href="#" class="font-32 order_btn text-center bg_orange" data-type="1">取菜 </a> </div></div> </div>';
                            } else if (type == 3) {
                                if (!k[0]['number']) {
                                    _html += '<div class=" half2 "><div class="tb-mode meals"><div class=" tb-cell font-28"><div class="font-48"> ' + key + ' 111号</div> ' + _num + '</div></div> </div>';
                                } else {
                                    _html += '<div class=" half2 "><div class="tb-mode meals"><div class=" tb-cell font-28"><div class="font-48"> ' + key + ' 222号&nbsp;&nbsp;&nbsp;' + k[0]['number'] + '</div> ' + _num + '</div></div> </div>';
                                }
                            }
                            console.log(type)

                        });
                        page++;
                        select_ajax = true;
                        if (page > 1) {
                            $('.contain_child').append(_html);
                        } else {
                            $('.contain_child').html(_html);
                        }
                        if (data.data == '') {
                            $('.contain_child').append('<div class="text-center" style="padding: 20px 0">没有数据啦~</div>');
                            select_ajax = false;
                        }
                    }
                }
            });
        }



        $(document).on("click", ".meals_number", function () {
            $(this).toggleClass('active_number');
            _$this = $(this);
            /*len = $(this).parents('.font-28').find('.meals_number').length;
             activeLen = $(this).parents('.font-28').find('.active_number').length;*/
        });
        $('.pop-box').on('click', '.pop-btn', function () {
            $('.pop-box').addClass('hide');
        });
        $(document).on("click", ".order_btn", function () {
            len = $(this).parents('.meals').find('.meals_number').length;
            activeLen = $(this).parents('.meals').find('.active_number').length;
            orderThis = $(this);
            var Arr = '';
            $(this).parents('.meals').find('.active_number').each(function () {
                Arr += $(this).attr('value') + ',';
            });
            var ty = $(".type").val();
            if (!Arr) {
                //$.alert('error','请选择对应的菜品桌号');
                fm.alert("请选择对应的菜品桌号");
                return false;
            }
            doType(Arr, ty);
        });
        function doType(Arr, ty) {
            $.ajax({
                url: '/restaurantstyy/ZduScreen/doType',
                type: 'POST',
                data: {type: ty, restaurant_id: restaurantId, ogid: Arr},
                dataType: 'JSON',
                success: function (data) {
                    if (data.status == 'S') {
                        fm.alert(data.message);
                        if (len == activeLen) {
                            orderThis.parents('.half2').remove();
                        } else {
                            orderThis.parents('.meals').find('.active_number').remove();
                        }
                        /*reload()*/
                    } else {
                        fm.alert(data.message);
                        /*reload()*/
                    }
                }
            })
        }

        /*$('.order_btn').click(function () {

         /!*var texts = '确定' + $.trim($(this).html()) + '？';
         type = $(this).attr('data-style');
         og_id = $(this).attr('data-ogid');
         $('.pop-box').find('.hint-txt').text(texts);
         $('.pop-box').removeClass('hide');
         return false;*!/
         });*/

        $('.font-blue').click(function () {
            $.ajax({
                type: "post",
                url: "/restaurantstyy/ZduScreen/doType",
                data: {
                    og_id: og_id,
                    type: type
                },
                dataType: "json",
                success: function (res) {
                    if (res == 1) {
                        fm.alert('操作成功');

                    } else {
                        fm.alert('操作失败')
                    }
                    window.location.reload();
                }
            })
        });
//刷新页面
        /*  function reload() {
         setTimeout('location.reload()', 3000);
         }*/

    });

</script>

<!--<script>
    var wAlert = window.alert;
    window.alert = function (message) {
        try {
            var iframe = document.createElement("IFRAME");
            iframe.style.display = "none";
            iframe.setAttribute("src", 'data:text/plain,');
            document.documentElement.appendChild(iframe);
            var alertFrame = window.frames[0];
            var iwindow = alertFrame.window;
            if (iwindow == undefined) {
                iwindow = alertFrame.contentWindow;
            }
            iwindow.alert(message);
            iframe.parentNode.removeChild(iframe);
        }
        catch (exc) {
            return wAlert(message);
        }
    }

</script>-->

